//
//  TSCVCStoryPage.m
//  Tsc_IOS
//
//  Created by Rio on 15-5-12.
//  Copyright (c) 2015年 idream. All rights reserved.
//

#import "TSCVCStoryPage.h"
#import "TSCSDK.h"

@interface TSCVCStoryPage ()

@end

@implementation TSCVCStoryPage


+ (id)vcStoryPageWithStoryboard {
    UIStoryboard * sb = [UIStoryboard storyboardWithName:UI_STORYBOARD_NAME_MAIN bundle:[NSBundle mainBundle]];
    return [sb instantiateViewControllerWithIdentifier:UI_VC_NAME_STORY_PAGE];
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 参数检查：在显示当前页之前，需先设置各种显示属性
    //    NSAssert(_pageInde, <#desc, ...#>) // 注：_pageIndex不用校验
    NSAssert([TSCMyUtil isStringEmpty:_pageTitle] == NO, @"[E]%s: 显示“我们的故事”这一页[%@]时，未初始化_pageTitle！", __FUNCTION__, self);
    NSAssert([TSCMyUtil isStringEmpty:_imgName] == NO, @"[E]%s: 显示“我们的故事”这一页[%@]时，未初始化_imgName！", __FUNCTION__, self);
    NSAssert([TSCMyUtil isStringEmpty:_btnText] == NO, @"[E]%s: 显示“我们的故事”这一页[%@]时，未初始化_btnText！", __FUNCTION__, self);
    NSAssert(_totalPageNum > 0, @"[E]%s: 显示“我们的故事”这一页[%@]时，_totalPageNum[%li]必须大于0！", __FUNCTION__, self, _totalPageNum);
    
    _lbTitle.text = _pageTitle;
    _ivStory.image = [UIImage imageNamed:_imgName];
    [_btnNext setTitle:_btnText forState:UIControlStateNormal];
    _lbPageNum.text = [NSString stringWithFormat:@"%li / %li", _pageIndex + 1, _totalPageNum];
    
    // 注册事件——“下一步”按钮
    // 注：仅当最后一页时，才注册事件
    if (_pageIndex == _totalPageNum - 1) {
        [_btnNext addTarget:self action:@selector(btnNextClicked) forControlEvents:UIControlEventTouchUpInside];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

#pragma mark delegate

- (void) btnNextClicked {
    
    // 关闭当前界面
    // 注：谁打开，谁关闭
    [_pvc.parentViewController dismissViewControllerAnimated:YES completion:nil];
    
}

@end
